package com.yks.pls;

import org.apache.commons.codec.binary.Hex;

import java.math.BigInteger;
import java.util.Base64;

public class Base64TOHex {
    public static void main(String[] args) {
        String guid = "ADQwNDA0OTAwMTExOTIzMTAwMTM1MTI2OUY5MjhEMjdBREMwRTAzMDcwQTcxMzMyMzIz";
        byte[] decoded = Base64.getDecoder().decode(guid);
        System.out.println(toHex(decoded));
        String.format("%040x", new BigInteger(1, decoded));
        final String s = new BigInteger(1, decoded).toString(16);
        System.out.println(s);
//        String guid = "ADQwNDA0OTAwMTExOTIzMTAwMTM1MTI2OUY5MjhEMjdBREMwRTAzMDcwQTcxMzMyMzIz";
//        byte[] decoded = Base64.getDecoder().decode(guid);
//        System.out.println(String.format("%040x", new BigInteger(1, decoded)));
//        test();
    }

    private static void test(){
        String guid = "ADQwNDA0OTAwMTExOTIzMTAwMTM1MTI2OUY5MjhEMjdBREMwRTAzMDcwQTcxMzMyMzIz";
        byte[] decoded = org.apache.commons.codec.binary.Base64.decodeBase64(guid);
        String hexString = Hex.encodeHexString(decoded);
        System.out.println(hexString);

    }
    private static final char[] DIGITS
            = {'0', '1', '2', '3', '4', '5', '6', '7',
            '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

    public static final String toHex(byte[] data) {
        final StringBuffer sb = new StringBuffer(data.length * 2);
        for (int i = 0; i < data.length; i++) {
            sb.append(DIGITS[(data[i] >>> 4) & 0x0F]);
            sb.append(DIGITS[data[i] & 0x0F]);
        }
        return sb.toString();

    }
}
